package com.android.taski;


import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.app.ListActivity;
import android.content.Intent;



public class ReminderListActivity extends ListActivity {
    private static final int ACTIVTY_CREATE = 0;
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.reminder_list);
        String[] sMesBulles = new String[] {"Truc","Pow","Blop","Wizz"};
        ArrayAdapter <String> adapter = new ArrayAdapter <String> (this, R.layout.reminder_row, R.id.text1, sMesBulles);
        setListAdapter(adapter);
        registerForContextMenu(getListView());
        if (getIntent() != null) {
        	Bundle extras = getIntent().getExtras();
        	int rowId = extras != null ? extras.getInt("RowId") : -1;
        }
    }
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
    	super.onListItemClick(l, v, position, id);
    	Intent i = new Intent(this, ReminderEditActivity.class);
    	i.putExtra("RowID", id);
    	startActivity(i);
    }
    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    	super.onCreateContextMenu(menu, v, menuInfo);
    	MenuInflater mi = getMenuInflater();
    	mi.inflate(R.menu.list_menu_item_longpress, menu);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    	super.onCreateOptionsMenu(menu);
    	MenuInflater mi = getMenuInflater();
    	mi.inflate(R.menu.list_menu, menu);
    	return true;
    }
    @Override
    public boolean onMenuItemSelected(int featureId, MenuItem item) {
    	switch(item.getItemId()) {
    		case R.id.menu_insert:createReminder();
    		return true;
    	}
    	return super.onMenuItemSelected(featureId, item);
    }
    private void createReminder() {
    	Intent i = new Intent(this, ReminderEditActivity.class);
    	startActivityForResult(i, ACTIVTY_CREATE);
    }
    @Override
    protected void onActivityResult(int requestCode,int resultCode,Intent intent) {
    	super.onActivityResult(requestCode, resultCode, intent);
    }
    @Override
    public boolean onContextItemSelected(MenuItem item) {
    	switch(item.getItemId()) {
    	case R.id.menu_delete:return true;
    	}
    	return super.onContextItemSelected(item);
    }
    
}